﻿<UserControl x:Class="LockCrypt.HotkeyMapper"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:lex="http://schemas.root-project.org/xaml/presentation"
    xmlns:conv="clr-namespace:LockCrypt.Converters"
    x:Name="root" Loaded="UserControl_Loaded">
    <UserControl.Resources>
        <conv:HotkeyConverter x:Key="HotkeyConverter"/>
        <conv:BoolToInvertedVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="3*"/>
            <ColumnDefinition Width="3*"/>
            <ColumnDefinition Width="3*"/>
        </Grid.ColumnDefinitions>
        <Grid.Resources>
            <Style TargetType="{x:Type CheckBox}" BasedOn="{StaticResource {x:Type CheckBox}}">
                <EventSetter Event="Checked" Handler="chk_Changed"/>
                <EventSetter Event="Unchecked" Handler="chk_Changed"/>
            </Style>
        </Grid.Resources>
        <CheckBox x:Name="chkCtrl" Grid.Row="0" Grid.Column="0" Content="{lex:LocText LockCrypt.Core:Strings:Ctrl}" IsChecked="{Binding ShortcutKey,ElementName=root,Mode=OneWay,Converter={StaticResource HotkeyConverter},ConverterParameter=ctrl}"/>
        <CheckBox x:Name="chkShift" Grid.Row="0" Grid.Column="1" Content="{lex:LocText LockCrypt.Core:Strings:Shift}" IsChecked="{Binding ShortcutKey,ElementName=root,Mode=OneWay,Converter={StaticResource HotkeyConverter},ConverterParameter=shift}"/>
        <CheckBox x:Name="chkAlt" Grid.Row="0" Grid.Column="2" Content="{lex:LocText LockCrypt.Core:Strings:Alt}" IsChecked="{Binding ShortcutKey,ElementName=root,Mode=OneWay,Converter={StaticResource HotkeyConverter},ConverterParameter=alt}"/>
        <StackPanel Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Orientation="Horizontal">
            <Label Content="{lex:LocText LockCrypt.Core:Strings:Key}"/>
            <TextBox x:Name="txtKey" Text="{Binding ShortcutKey,ElementName=root,Mode=OneWay,Converter={StaticResource HotkeyConverter},ConverterParameter=key}" 
                 TextChanged="chk_Changed" MaxLength="1" MinWidth="22"/>
        </StackPanel>
        <!--ContentControl Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <ContentControl.Style>
                <Style TargetType="{x:Type ContentControl}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ContentControl}">
                                <ControlTemplate.Resources>
                                    <Storyboard x:Key="VisibleOn">
                                        <DoubleAnimation Duration="00:00:01" Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" From="0" To="1"/>
                                    </Storyboard>
                                    <Storyboard x:Key="VisibleOff">
                                        <DoubleAnimation Duration="00:00:01" Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" To="0"/>
                                    </Storyboard>
                                </ControlTemplate.Resources>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="Visibility" Value="Visible">
                                        <Trigger.EnterActions>
                                            <BeginStoryboard Storyboard="{StaticResource VisibleOn}"/>
                                        </Trigger.EnterActions>
                                        <Trigger.ExitActions>
                                            <BeginStoryboard Storyboard="{StaticResource VisibleOff}"/>
                                        </Trigger.ExitActions>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ContentControl.Style-->
            <Border Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Margin="0,4,0,0" Background="#FFDFDF" BorderThickness="1" BorderBrush="{StaticResource SolidBorderBrush}" CornerRadius="1"
                    Visibility="{Binding IsShortcutValid,ElementName=root,Mode=OneWay,Converter={StaticResource BooleanToVisibilityConverter}}">
                <Grid Margin="4">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Image Grid.Column="0" Source="pack://application:,,,/Resources/images/error_16.png" Width="16" VerticalAlignment="Center" Margin="0,0,5,0"/>
                    <TextBlock Grid.Column="1" Text="{lex:LocText LockCrypt.Core:Strings:ShortcutUnavailable}" VerticalAlignment="Center"/>
                </Grid>
            </Border>
        
    </Grid>
</UserControl>
